export default {
  namespaced: true,
  state: {
    goodsList: []
  },
  mutations: {
    addToCart (state, goods) {
      const findGoods = state.goodsList.find(
        item => item.goods_id === goods.goods_id
      )
      // 如果购物车中之前存在，则把数量累加
      if (findGoods) {
        findGoods.goods_number += goods.goods_number
      } else {
        state.goodsList.push(goods)
      }

      // 保存到本地
      uni.setStorageSync('cart', state.goodsList)
    }
  }
}
